//
//  YYLPolyLine.m
//  YYLSport
//
//  Created by yangyinglei on 2017/4/22.
//  Copyright © 2017年 yangyinglei. All rights reserved.
//

#import "YYLPolyLine.h"

@implementation YYLPolyLine

+ (instancetype)PolylineWithSourceLocation: (CLLocation*)source andDest: (CLLocation*)dest {


    //构造折线数据对象
    CLLocationCoordinate2D commonPolylineCoords[2];
    commonPolylineCoords[0].latitude = source.coordinate.latitude;
    commonPolylineCoords[0].longitude = source.coordinate.longitude;
    
    commonPolylineCoords[1].latitude = dest.coordinate.latitude;
    commonPolylineCoords[1].longitude = dest.coordinate.longitude;
    
    
    //构造折线对象
    YYLPolyLine *commonPolyline = [YYLPolyLine polylineWithCoordinates:commonPolylineCoords count:2];
    //计算速度
    [commonPolyline calculateSpeedWithSourceLocation:source andDest:dest];
    return commonPolyline;
    
}

- (void)calculateSpeedWithSourceLocation: (CLLocation*)source andDest: (CLLocation*)dest{
    _speed = (source.speed + dest.speed) / 2 * 3.6;  //米每秒 转换成 公里每小时
    _strokeColor = [UIColor colorWithRed:(_speed * 0.033) green:1 blue:0 alpha:1];
}
@end
